overview.t[i,1] <- d.tt$cage[1]
overview.t[i, 2:ncol(overview.t)] <- apply(d.tt[, c((ncol(d.tt) - length(wavelength.range) + 1):ncol(d.tt))], 2, mean)
}
head(overview.t)
for(i in 1:length(unique.cage)){
#i <- 1
d.tt <- irr.data.t2[irr.data.t2$cage == unique.cage[i],]
overview.t[i,1] <- d.tt$cage[1]
overview.t[i, 2:ncol(overview.t)] <- apply(d.tt[, c((ncol(d.tt) - length(wavelength.range) + 1):ncol(d.tt))], 2, mean)
}
head(overview.t)
unique.cage
overview.t <- as.data.frame(matrix(NA, nrow = length(unique.cage), ncol= length(wavelength.irr) + 1))
colnames(overview.t) <- c("cage", wavelength.irr)
overview.t
str(irr.data.t2)
i <- 1
d.tt <- irr.data.t2[irr.data.t2$cage == unique.cage[i],]
d.tt
overview.t[i,1] <- d.tt$cage[1]
overview.t[i,1]
overview.t[i, 2:ncol(overview.t)] <- apply(d.tt[, c((ncol(d.tt) - length(wavelength.range) + 1):ncol(d.tt))], 2, mean)
warnings()
d.tt[, c((ncol(d.tt) - length(wavelength.range) + 1):ncol(d.tt))]
apply(d.tt[, c((ncol(d.tt) - length(wavelength.range) + 1):ncol(d.tt))], 2, mean)
i <- 1
d.tt <- irr.data.t2[irr.data.t2$cage == unique.cage[i],]
d.tt
apply(d.tt[, -c(1:6)], 2, mean)
for(i in 1:length(unique.cage)){
# i <- 1
d.tt <- irr.data.t2[irr.data.t2$cage == unique.cage[i],]
overview.t[i,1] <- d.tt$cage[1]
overview.t[i, 2:ncol(overview.t)] <- apply(d.tt[, -c(1:6)], 2, mean)
}
head(overview.t)
irr.treatments <- cbind.data.frame(substr(overview.t$cage, 3,3), overview.t[, -1])
colnames(irr.treatments)[1] <- "Treatment"
str(irr.treatments)
f.irradiance.bootstrap <- function(n.iter, data.irradiance){
colnames(data.irradiance) <- c("Treatment", wavelength.range)
orig.treat <- factor(data.irradiance[, 1])
null.F <- matrix(NA, nrow = n.iter, ncol = length(wavelength.range))
t.start <- proc.time()
for(i in 1:n.iter){
print(paste("iteration # = ", i, sep = ""))
#i <- 1
new.levels <- factor(sample(orig.treat, length(orig.treat), replace = FALSE))
for(j in 1:length(wavelength.range)){
#j <- 1
null.F[i, j] <- summary(lm(data.irradiance[, j+1] ~ new.levels))$fstatistic[1]
#str(m1)
}
}
# runtime is
run.time <- proc.time() - t.start
# in minutes
run.time/60
# for the 'original data'
real.F <- rep(NA, length(wavelength.range))
for(i in 1:length(wavelength.range))real.F[i] <- summary(lm(data.irradiance[, i+1] ~ orig.treat))$fstatistic[1]
# use the sum of each row of F values for our null distribution
null.F.sum <- apply(null.F,1, sum)
real.F.sum <- sum(real.F)
# visualise the null-distribution and the F value of the actual data
hist(null.F.sum)
abline(v = real.F.sum, col = "red")
# get the p value
length(null.F.sum[ null.F.sum >= real.F.sum])/length(null.F.sum)
# make a list to sens boostrap output back
irr.bootstrap <- vector("list", 4)
irr.bootstrap[[1]] <- null.F
irr.bootstrap[[2]] <- real.F
irr.bootstrap[[3]] <- null.F.sum
irr.bootstrap[[4]] <- real.F.sum
return(irr.bootstrap)
}
irr.exp.permut <- f.irradiance.bootstrap(10,irr.treatments)
irr.exp.permut <- f.irradiance.bootstrap(10,irr.treatments)
f.irradiance.bootstrap <- function(n.iter, data.irradiance){
colnames(data.irradiance) <- c("Treatment", wavelength.range)
orig.treat <- factor(data.irradiance[, 1])
null.F <- matrix(NA, nrow = n.iter, ncol = length(wavelength.range))
t.start <- proc.time()
for(i in 1:n.iter){
print(paste("iteration # = ", i, sep = ""))
#i <- 1
new.levels <- factor(sample(orig.treat, length(orig.treat), replace = FALSE))
for(j in 1:length(wavelength.range)){
#j <- 1
null.F[i, j] <- summary(lm(data.irradiance[, j+1] ~ new.levels))$fstatistic[1]
#str(m1)
}
}
# runtime is
run.time <- proc.time() - t.start
# in minutes
run.time/60
# for the 'original data'
real.F <- rep(NA, length(wavelength.range))
for(i in 1:length(wavelength.range))real.F[i] <- summary(lm(data.irradiance[, i+1] ~ orig.treat))$fstatistic[1]
# use the sum of each row of F values for our null distribution
null.F.sum <- apply(null.F,1, sum)
real.F.sum <- sum(real.F)
# visualise the null-distribution and the F value of the actual data
hist(null.F.sum)
abline(v = real.F.sum, col = "red")
# get the p value
length(null.F.sum[ null.F.sum >= real.F.sum])/length(null.F.sum)
# make a list to sens boostrap output back
irr.bootstrap <- vector("list", 4)
irr.bootstrap[[1]] <- null.F
irr.bootstrap[[2]] <- real.F
irr.bootstrap[[3]] <- null.F.sum
irr.bootstrap[[4]] <- real.F.sum
return(irr.bootstrap)
}
irr.treatments
irr.exp.permut <- f.irradiance.bootstrap(10, irr.treatments)
str(irr.treatments)
irr.exp.permut <- f.irradiance.bootstrap(10, irr.treatments)
traceback()
str(irr.treatments)
n.iter <- 10
data.irradiance <- irr.treatments
colnames(data.irradiance) <- c("Treatment", wavelength.range)
wavelength.range
f.irradiance.bootstrap <- function(n.iter, data.irradiance){
# n.iter <- 10
# data.irradiance <- irr.treatments
colnames(data.irradiance) <- c("Treatment", wavelength.irr)
orig.treat <- factor(data.irradiance[, 1])
null.F <- matrix(NA, nrow = n.iter, ncol = length(wavelength.irr))
t.start <- proc.time()
for(i in 1:n.iter){
print(paste("iteration # = ", i, sep = ""))
#i <- 1
new.levels <- factor(sample(orig.treat, length(orig.treat), replace = FALSE))
for(j in 1:length(wavelength.irr)){
#j <- 1
null.F[i, j] <- summary(lm(data.irradiance[, j+1] ~ new.levels))$fstatistic[1]
#str(m1)
}
}
# runtime is
run.time <- proc.time() - t.start
# in minutes
run.time/60
# for the 'original data'
real.F <- rep(NA, length(wavelength.irr))
for(i in 1:length(wavelength.irr))real.F[i] <- summary(lm(data.irradiance[, i+1] ~ orig.treat))$fstatistic[1]
# use the sum of each row of F values for our null distribution
null.F.sum <- apply(null.F,1, sum)
real.F.sum <- sum(real.F)
# visualise the null-distribution and the F value of the actual data
hist(null.F.sum)
abline(v = real.F.sum, col = "red")
# get the p value
length(null.F.sum[ null.F.sum >= real.F.sum])/length(null.F.sum)
# make a list to sens boostrap output back
irr.bootstrap <- vector("list", 4)
irr.bootstrap[[1]] <- null.F
irr.bootstrap[[2]] <- real.F
irr.bootstrap[[3]] <- null.F.sum
irr.bootstrap[[4]] <- real.F.sum
return(irr.bootstrap)
}
irr.treatments <- cbind.data.frame(substr(overview.t$cage, 3,3), overview.t[, -1])
colnames(irr.treatments)[1] <- "Treatment"
str(irr.treatments)
irr.exp.permut <- f.irradiance.bootstrap(10, irr.treatments)
(length(irr.exp.permut[[3]][ irr.exp.permut[[3]] >= irr.exp.permut[[4]]]) + 1) / (1000 + 1)
write.csv(irr.exp.permut[[3]], paste(path.output.exp, "F.null.distr.irradiance.cages.n.runs_",n.runs, ".csv", sep = ""))
str(exp.data.1)
head()
head(exp.data.1)
tail(exp.data.1)
write.csv(exp.data.1, paste(path.data, "/metaData/experimental.fish.csv", sep=""), row.names = FALSE)
exp.data.1
?rm()
rm(exp.data.1)
exp.data.1
exp.data.1 <- read.csv(paste(path.data, "/metaData/experimental.fish.csv", sep=""), stringsAsFactors = FALSE)
data.opsin <- read.csv(paste(path.data, "data.opsin.csv", sep = ""), stringsAsFactors = FALSE)
opsin.exp <- merge(data.opsin, exp.data.1[, c(1:7,10:14)], by = "IndivName")
treat <- substr(opsin.exp[,1], 3, 3)
opsin.exp <- as.data.frame(append(opsin.exp, list(treat), after = 1))
colnames(opsin.exp)[2] <- "treatment"
levels(opsin.exp$treatment) <- c("deep", "medium")
opsin.exp$pair <- substr(opsin.exp$IndivName,1,2)
pdf(paste(path.figures, "Fig 3 Rel exp opsin experiment sex  medium - deep.pdf"), width = 7, height = 7)
fig.opsin.sex.expr(na.omit(opsin.exp[,c(2,5:8,12)]))
str(opsin.exp)
fish.added <- exp.data.1[exp.data.1$fish.order == 2,]
table(fish.added$gender)
fish.retrapped <- exp.data.1[exp.data.1$retrap == "yes",]
table(fish.retrapped$gender)
max(exp.data.1$time.in.cage, na.rm = TRUE)
which(is.na(opsin.exp$SWS1))
opsin.exp.1 <- opsin.exp[ -which(is.na(opsin.exp$SWS1)),]
exp.SWS1.m.0 <- lmer(SWS1 ~ gender * treatment + (1|pair), opsin.exp.1, REML = FALSE)
summary(exp.SWS1.m.0)
exp.SWS1.m.1 <- lmer(SWS1 ~ gender + treatment + (1|pair), opsin.exp.1, REML = FALSE)
summary(exp.SWS1.m.1)
anova(exp.SWS1.m.0, exp.SWS1.m.1)
exp.SWS1.m.2 <- lmer(SWS1 ~ gender +  (1|pair), opsin.exp.1, REML = FALSE)
summary(exp.SWS1.m.2)
exp.data.1[, c(1:7,10:14)]
col.t2 <- col.t[5:6]
alpha1 <- 91
exp.data.1 <- read.csv(paste(path.data, "/metaData/experimental.fish.csv", sep=""), stringsAsFactors = FALSE)
rm(exp.data.1)
<
data.opsin <- read.csv(paste(path.data, "data.opsin.csv", sep = ""), stringsAsFactors = FALSE)
opsin.exp <- merge(data.opsin, exp.data.1, by = "IndivName")
exp.data.1 <- read.csv(paste(path.data, "/metaData/experimental.fish.csv", sep=""), stringsAsFactors = FALSE)
data.opsin <- read.csv(paste(path.data, "data.opsin.csv", sep = ""), stringsAsFactors = FALSE)
opsin.exp <- merge(data.opsin, exp.data.1, by = "IndivName")
treat <- substr(opsin.exp[,1], 3, 3)
opsin.exp <- as.data.frame(append(opsin.exp, list(treat), after = 1))
opsin.exp
colnames(opsin.exp)[2] <- "treatment"
levels(opsin.exp$treatment) <- c("deep", "medium")
opsin.exp$pair <- substr(opsin.exp$IndivName,1,2)
pdf(paste(path.figures, "Fig 3 Rel exp opsin experiment sex  medium - deep.pdf"), width = 7, height = 7)
fig.opsin.sex.expr(na.omit(opsin.exp[,c(2,5:8,12)]))
dev.off()
opsin.exp
fig.opsin.sex.expr(na.omit(opsin.exp[,c(2,5:8,11)]))
pdf(paste(path.figures, "Fig 3@ Rel exp opsin experiment sex  medium - deep.pdf"), width = 7, height = 7)
fig.opsin.sex.expr(na.omit(opsin.exp[,c(2,5:8,11)]))
dev.off()
pdf(paste(path.figures, "Fig 3 Rel exp opsin experiment sex  medium - deep.pdf"), width = 7, height = 7)
fig.opsin.sex.expr(na.omit(opsin.exp[,c(2,5:8,11)]))
dev.off()
str(opsin.exp)
fish.added <- exp.data.1[exp.data.1$fish.order == 2,]
table(fish.added$gender)
fish.retrapped <- exp.data.1[exp.data.1$retrap == "yes",]
table(fish.retrapped$gender)
max(exp.data.1$time.in.cage, na.rm = TRUE)
which(is.na(opsin.exp$SWS1))
opsin.exp.1 <- opsin.exp[ -which(is.na(opsin.exp$SWS1)),]
exp.SWS1.m.0 <- lmer(SWS1 ~ gender * treatment + (1|pair), opsin.exp.1, REML = FALSE)
summary(exp.SWS1.m.0)
exp.SWS1.m.1 <- lmer(SWS1 ~ gender + treatment + (1|pair), opsin.exp.1, REML = FALSE)
summary(exp.SWS1.m.1)
anova(exp.SWS1.m.0, exp.SWS1.m.1)
exp.SWS1.m.2 <- lmer(SWS1 ~ gender +  (1|pair), opsin.exp.1, REML = FALSE)
sc.exp <- transform.sum.constr(opsin.exp.1[,c(1,5:8)])
sc.exp
sensit.exp.opsin <- na.omit(opsin.exp[, c(2,5:8)])
sensit.exp.opsin
opsin.exp.1
head(opsin.exp.1)
opsin.exp.2 <- opsin.exp.1[, c(1,2,5:8,1,16)]
opsin.exp.3 <- na.omit(opsin.exp.2)
delta.opsin <- opsin.origin <- data.frame(matrix(NA, nrow = nrow(opsin.exp.3), ncol = 4))
colnames(opsin.origin) <- c("SWS1.o", "SWS2.o", "RH2.o", "LWS.o")
colnames(delta.opsin) <- c("SWS1.d", "SWS2.d", "RH2.d", "LWS.d")
for(i in 1:nrow(opsin.exp.3)){
# go through each opsin
for(j in 1:4){
#j <- 1
d <- opsin.exp.3$depth[i]
opsin.exp.o <- coeff.ops$intercept.m[j] + d * coeff.ops$slope.m[j]
opsin.origin[i, j] <- opsin.exp.o
}
}
i <- 1
j <- 1
d <- opsin.exp.3$depth[i]
d
opsin.exp.3
opsin.exp.1
opsin.exp.2 <- opsin.exp.1[, c(1,2,5:8,13,16)]
opsin.exp.3 <- na.omit(opsin.exp.2)
delta.opsin <- opsin.origin <- data.frame(matrix(NA, nrow = nrow(opsin.exp.3), ncol = 4))
colnames(opsin.origin) <- c("SWS1.o", "SWS2.o", "RH2.o", "LWS.o")
colnames(delta.opsin) <- c("SWS1.d", "SWS2.d", "RH2.d", "LWS.d")
for(i in 1:nrow(opsin.exp.3)){
i <- 1
# go through each opsin
for(j in 1:4){
#j <- 1
d <- opsin.exp.3$depth[i]
opsin.exp.o <- coeff.ops$intercept.m[j] + d * coeff.ops$slope.m[j]
opsin.origin[i, j] <- opsin.exp.o
}
}
opsin.origin[opsin.origin < 0]
sums <- apply(opsin.origin, 1, sum)
for(i in 1:nrow(opsin.origin)) opsin.origin[i,] <- opsin.origin[i,]/sums[i]
depth.exp <- rep(0, nrow(opsin.exp.3))
depth.exp[which(opsin.exp.3$treatment == "medium")] <- 1.5
depth.exp[which(opsin.exp.3$treatment == "deep")] <- 2
delta.depth <- opsin.exp.3$depth - depth.exp
delta.opsin <- opsin.origin - opsin.exp.3[,3:6]
colnames(delta.opsin) <- c("SWS1.d", "SWS2.d", "RH2.d", "LWS.d")
opsin.pl <- cbind(opsin.exp.3, opsin.origin, delta.opsin, delta.depth)
sex <- "male"
opsin.pl.m <- opsin.pl[opsin.pl$gender == sex,]
par(mfrow=c(1,1))
pos.deep <- which(opsin.pl.m$treatment == "deep")
pos.shallow <- which(opsin.pl.m$treatment == "shallow")
m.pl1 <- lm( opsin.pl.m$SWS1.d ~ opsin.pl.m$delta.depth)
plot(opsin.pl.m$delta.depth, opsin.pl.m$SWS1.d)
summary(m.pl1)
plot(m.pl1)
fig.opsin.plast(opsin.pl.m[, c(2,13,15,14,16,17)])
opsin.pl.m
col.t2 <- col.t[5:6]
alpha1 <- 91
exp.data.1 <- read.csv(paste(path.data, "/metaData/experimental.fish.csv", sep=""), stringsAsFactors = FALSE)
data.opsin <- read.csv(paste(path.data, "data.opsin.csv", sep = ""), stringsAsFactors = FALSE)
opsin.exp <- merge(data.opsin, exp.data.1[, c(1:7,10:14)], by = "IndivName")
exp.data.1 <- read.csv(paste(path.data, "/metaData/experimental.fish.csv", sep=""), stringsAsFactors = FALSE)
meta.d.exp <- read.csv(paste(path.data, "/metaData/experimental.fish.all.csv", sep=""), stringsAsFactors = FALSE)
# str(meta.d.exp)
meta.d.exp$time.col.min <- f.time.to.min(meta.d.exp$time.caught)
# seperate the data from when we caught the fish (pre) from the fish data at the end (post)
pre <- meta.d.exp[meta.d.exp$timing != "post",]
colnames(pre)[7] <- "date.pre"
post <- meta.d.exp[meta.d.exp$timing == "post",]
colnames(post)[7] <- "date.post"
# merge and work with the date and time
exp.data <- merge(post[,c(1:7, 30:31)], pre[,c(7,9:11,30)], by = "IDcom")
head(exp.data)
exp.data$timing
exp.data <- subset(exp.data, select = -c(time.col.min))
exp.data$time.in.cage <- exp.data$date.post - exp.data$date.pre
IndivName <- exp.data$FishID
exp.data.1 <- as.data.frame(append(exp.data, list(IndivName), after = 1))
colnames(exp.data.1)[2] <- "IndivName"
exp.data.1$IndivName <- as.character(exp.data.1$IndivName)
for(i in 1:nrow(exp.data.1)){
if(exp.data.1$gender[i] == "male") exp.data.1$IndivName[i] <- paste(exp.data.1$FishID[i], "M", sep = "")
if(exp.data.1$gender[i] == "female") exp.data.1$IndivName[i] <- paste(exp.data.1$FishID[i], "F", sep = "")
}
str(exp.data.1)
tail(exp.data.1)
write.csv(exp.data.1, paste(path.data, "/metaData/experimental.fish.csv", sep=""), row.names = FALSE)
rm(exp.data.1)
exp.data.1
exp.data.1 <- read.csv(paste(path.data, "/metaData/experimental.fish.csv", sep=""), stringsAsFactors = FALSE)
data.opsin <- read.csv(paste(path.data, "data.opsin.csv", sep = ""), stringsAsFactors = FALSE)
opsin.exp <- merge(data.opsin, exp.data.1[, c(1:7,10:14)], by = "IndivName")
treat <- substr(opsin.exp[,1], 3, 3)
opsin.exp <- as.data.frame(append(opsin.exp, list(treat), after = 1))
colnames(opsin.exp)[2] <- "treatment"
levels(opsin.exp$treatment) <- c("deep", "medium")
opsin.exp$pair <- substr(opsin.exp$IndivName,1,2)
pdf(paste(path.figures, "Fig 3 Rel exp opsin experiment sex  medium - deep.pdf"), width = 7, height = 7)
fig.opsin.sex.expr(na.omit(opsin.exp[,c(2,5:8,12)]))
pdf(paste(path.figures, "Fig 3 Rel exp opsin experiment sex  medium - deep.pdf"), width = 7, height = 7)
fig.opsin.sex.expr(na.omit(opsin.exp[,c(2,5:8,12)]))
dev.off()
str(opsin.exp)
fish.added <- exp.data.1[exp.data.1$fish.order == 2,]
table(fish.added$gender)
fish.retrapped <- exp.data.1[exp.data.1$retrap == "yes",]
table(fish.retrapped$gender)
max(exp.data.1$time.in.cage, na.rm = TRUE)
max(exp.data.1$time.in.cage, na.rm = TRUE)
which(is.na(opsin.exp$SWS1))
opsin.exp.1 <- opsin.exp[ -which(is.na(opsin.exp$SWS1)),]
exp.SWS1.m.0 <- lmer(SWS1 ~ gender * treatment + (1|pair), opsin.exp.1, REML = FALSE)
summary(exp.SWS1.m.0)
exp.SWS1.m.1 <- lmer(SWS1 ~ gender + treatment + (1|pair), opsin.exp.1, REML = FALSE)
summary(exp.SWS1.m.1)
anova(exp.SWS1.m.0, exp.SWS1.m.1)
exp.SWS1.m.2 <- lmer(SWS1 ~ gender +  (1|pair), opsin.exp.1, REML = FALSE)
summary(exp.SWS1.m.2)
anova(exp.SWS1.m.1, exp.SWS1.m.2)
exp.SWS1.m.3 <- lmer(SWS1 ~ (1|pair), opsin.exp.1, REML = FALSE)
summary(exp.SWS1.m.3)
anova(exp.SWS1.m.2, exp.SWS1.m.3)
exp.SWS2.m.0 <- lmer(SWS2 ~ gender * treatment + (1|pair), opsin.exp.1)
summary(exp.SWS2.m.0)
exp.SWS2.m.1 <- lmer(SWS2 ~ gender + treatment  + (1|pair), opsin.exp.1)
summary(exp.SWS2.m.1)
anova(exp.SWS2.m.0, exp.SWS2.m.1)
exp.RH2.m.0 <- lmer(RH2 ~ gender * treatment + (1|pair), opsin.exp.1)
summary(exp.RH2.m.0)
exp.RH2.m.1 <- lmer(RH2 ~ gender + treatment  + (1|pair), opsin.exp.1)
summary(exp.RH2.m.1)
anova(exp.RH2.m.0, exp.RH2.m.1)
exp.RH2.m.2 <- lmer(RH2 ~ treatment + (1|pair), opsin.exp.1)
summary(exp.RH2.m.2)
anova(exp.RH2.m.1, exp.RH2.m.2)
exp.RH2.m.3 <- lmer(RH2 ~  (1|pair), opsin.exp.1)
summary(exp.RH2.m.3)
anova(exp.RH2.m.2, exp.RH2.m.3)
exp.LWS.m.0 <- lmer(LWS ~ gender * treatment  + (1|pair), opsin.exp.1)
summary(exp.LWS.m.0)
exp.LWS.m.1 <- lmer(LWS ~ gender + treatment  + (1|pair), opsin.exp.1)
summary(exp.LWS.m.1)
anova(exp.LWS.m.0, exp.LWS.m.1)
exp.LWS.m.2 <- lmer(LWS ~ treatment + (1|pair), opsin.exp.1)
summary(exp.LWS.m.2)
anova(exp.LWS.m.1, exp.LWS.m.2)
exp.LWS.m.3 <- lmer(LWS ~ (1|pair), opsin.exp.1)
summary(exp.LWS.m.3)
anova(exp.LWS.m.2, exp.LWS.m.3)
sc.exp <- transform.sum.constr(opsin.exp.1[,c(1,5:8)])
sc.exp <- transform.sum.constr(opsin.exp.1[,c(1,5:8)])
colnames(sc.exp) <- paste("sc", colnames(sc.exp), sep = "")
opsin.exp.1.s.c <- data.frame(opsin.exp.1, sc.exp)
str(opsin.exp.1.s.c)
exp.scSWS1.m.0 <- lmer(scSWS1 ~ gender * treatment + (1|pair), opsin.exp.1.s.c)
summary(exp.scSWS1.m.0)
exp.scSWS1.m.1  <- lmer(scSWS1 ~ gender + treatment + (1|pair), opsin.exp.1.s.c)
summary(exp.scSWS1.m.1)
anova(exp.scSWS1.m.0, exp.scSWS1.m.1)
exp.scSWS1.m.2  <- lmer(scSWS1 ~ gender + (1|pair), opsin.exp.1.s.c)
summary(exp.scSWS1.m.2)
anova(exp.scSWS1.m.1, exp.scSWS1.m.2)
exp.scSWS1.m.3  <- lmer(scSWS1 ~  (1|pair), opsin.exp.1.s.c)
summary(exp.scSWS1.m.3)
anova(exp.scSWS1.m.2, exp.scSWS1.m.3)
exp.scSWS2.m.0 <- lmer(scSWS2 ~ treatment * gender + (1|pair), opsin.exp.1.s.c)
summary(exp.scSWS2.m.0)
exp.scSWS2.m.1 <- lmer(scSWS2 ~ treatment + gender + (1|pair), opsin.exp.1.s.c)
summary(exp.scSWS2.m.1)
anova(exp.scSWS2.m.0, exp.scSWS2.m.1)
exp.scRH2.m.0 <- lmer(scRH2 ~ treatment * gender + (1|pair), opsin.exp.1.s.c)
summary(exp.scRH2.m.0)
exp.scRH2.m.1 <- lmer(scRH2 ~ treatment + gender + (1|pair), opsin.exp.1.s.c)
summary(exp.scRH2.m.1)
anova(exp.scRH2.m.0, exp.scRH2.m.1)
exp.scRH2.m.2 <- lmer(scRH2 ~  treatment + (1|pair), opsin.exp.1.s.c)
summary(exp.scRH2.m.2)
anova(exp.scRH2.m.1, exp.scRH2.m.2)
exp.scRH2.m.3 <- lmer(scRH2 ~  (1|pair), opsin.exp.1.s.c)
summary(exp.scRH2.m.3)
anova(exp.scRH2.m.2, exp.scRH2.m.3)
exp.scLWS.m.0 <- lmer(scLWS ~ treatment *  gender + (1|pair), opsin.exp.1.s.c)
summary(exp.scLWS.m.0)
exp.scLWS.m.1  <- lmer(scLWS ~ treatment +  gender + (1|pair), opsin.exp.1.s.c)
summary(exp.scLWS.m.1)
anova(exp.scLWS.m.0, exp.scLWS.m.1)
exp.scLWS.m.2  <- lmer(scLWS ~   treatment + (1|pair), opsin.exp.1.s.c)
summary(exp.scLWS.m.2)
anova(exp.scLWS.m.1, exp.scLWS.m.2)
exp.scLWS.m.3  <- lmer(scLWS ~   (1|pair), opsin.exp.1.s.c)
summary(exp.scLWS.m.3)
anova(exp.scLWS.m.2, exp.scLWS.m.3)
absorb.A1_0.5 <- read.csv(paste(path.output,"absorbance.prop.A1_0.5.csv", sep = ""), stringsAsFactors = FALSE)
absorb.A1_1 <- read.csv(paste(path.output,"absorbance.prop.A1_1.csv", sep = ""), stringsAsFactors = FALSE)
absorb.A1_0 <- read.csv(paste(path.output,"absorbance.prop.A1_0.csv", sep = ""), stringsAsFactors = FALSE)
str(absorb.A1_0.5)
rownames(absorb.A1_0.5) <- rownames(absorb.A1_1) <-rownames(absorb.A1_0) <-absorb.A1_0.5[,1]
absorb.A1_0.5 <- absorb.A1_0.5[, -1]
absorb.A1_1 <- absorb.A1_1[, -1]
absorb.A1_0 <- absorb.A1_0[, -1]
colnames(absorb.A1_0.5) <- colnames(absorb.A1_1) <- colnames(absorb.A1_0) <- wavelength.range
sensit.exp.opsin <- na.omit(opsin.exp[, c(2,5:8)])
n.runs <- 10000
n.runs <- 10
f.sens.bootstrap(n.runs, sensit.exp.opsin, absorb.A1_0.5)
n.runs <- 2
# --- for absorb.A1_0.5 ---
sens.diff.exp <- f.sens.bootstrap(n.runs, sensit.exp.opsin, absorb.A1_0.5)
hist(sens.diff.exp[[3]])
abline(v = sens.diff.exp[[4]])
null.d <- sens.diff.exp[[3]]
(length(null.d[ null.d >= sens.diff.exp[[4]]]) + 1) / (n.runs + 1)
fig.sens.combined(sens.all.exp.med.deep)
coeff.ops <- read.csv(paste(path.output.nat, "coefficients.opsin.corr.csv", sep = ""), stringsAsFactors = FALSE)
head(opsin.exp.1)
opsin.exp.2 <- opsin.exp.1[, c(1,2,5:8,12,16)]
opsin.exp.3 <- na.omit(opsin.exp.2)
delta.opsin <- opsin.origin <- data.frame(matrix(NA, nrow = nrow(opsin.exp.3), ncol = 4))
colnames(opsin.origin) <- c("SWS1.o", "SWS2.o", "RH2.o", "LWS.o")
colnames(delta.opsin) <- c("SWS1.d", "SWS2.d", "RH2.d", "LWS.d")
for(i in 1:nrow(opsin.exp.3)){
# go through each opsin
for(j in 1:4){
d <- opsin.exp.3$depth[i]
opsin.exp.o <- coeff.ops$intercept.m[j] + d * coeff.ops$slope.m[j]
opsin.origin[i, j] <- opsin.exp.o
}
}
for(i in 1:nrow(opsin.exp.3)){
# go through each opsin
for(j in 1:4){
d <- opsin.exp.3$depth[i]
opsin.exp.o <- coeff.ops$intercept.m[j] + d * coeff.ops$slope.m[j]
opsin.origin[i, j] <- opsin.exp.o
}
}
for(i in 1:nrow(opsin.exp.3)){
# go through each opsin
for(j in 1:4){
d <- opsin.exp.3$depth[i]
opsin.exp.o <- coeff.ops$intercept.m[j] + d * coeff.ops$slope.m[j]
opsin.origin[i, j] <- opsin.exp.o
}
}
opsin.origin[opsin.origin < 0]
sums <- apply(opsin.origin, 1, sum)
for(i in 1:nrow(opsin.origin)) opsin.origin[i,] <- opsin.origin[i,]/sums[i]
depth.exp <- rep(0, nrow(opsin.exp.3))
depth.exp[which(opsin.exp.3$treatment == "medium")] <- 1.5
depth.exp[which(opsin.exp.3$treatment == "deep")] <- 2
delta.depth <- opsin.exp.3$depth - depth.exp
delta.opsin <- opsin.origin - opsin.exp.3[,3:6]
colnames(delta.opsin) <- c("SWS1.d", "SWS2.d", "RH2.d", "LWS.d")
opsin.pl <- cbind(opsin.exp.3, opsin.origin, delta.opsin, delta.depth)
sex <- "male"
opsin.pl.m <- opsin.pl[opsin.pl$gender == sex,]
fig.opsin.plast(opsin.pl.m[, c(2,13,15,14,16,17)])
